using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Input.Touch;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework;
namespace MemoryGame
{

    class InputState
    {
        //public TouchCollection TouchState;
        // public readonly List<GestureSample> Gestures = new List<GestureSample>();
        //for touch engine

        public const int MAX_TOUCH_POINTER = 2;
        public static int m_currentNumPointer = 0;
        public static TouchLocationState[] arraytouchState = new TouchLocationState[MAX_TOUCH_POINTER];
        public static int[] arraytouchPosX = new int[MAX_TOUCH_POINTER];
        public static int[] arraytouchPosY = new int[MAX_TOUCH_POINTER];
        static KeyboardState keyboardState;

        public static bool misbackkeyPress = false;
        public InputState()
        {
        }

        public static bool isBackKeyPress()
        {
            return misbackkeyPress;

        }

        public static void UpdateTouchKey()
        {

            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
            {
                int i = 0;
                i++;
            }
        }
        public static void UpdateTouch()
        {
            int i = -1;
            m_currentNumPointer = -1;
            foreach (TouchLocation location in TouchPanel.GetState())
            {
                i++; 
                if (i >= MAX_TOUCH_POINTER)
                {
                    i--;
                    break;
                }
                //TouchLocationState.Invalid;
                //TouchLocationState.Moved;
                //TouchLocationState.Pressed;
                //TouchLocationState.Released;
                arraytouchState[i] = location.State;
                System.Console.WriteLine("arraytouchState[i]: %d", arraytouchState[i]);
                arraytouchPosX[i] = (int)location.Position.X;
                arraytouchPosY[i] = (int)location.Position.Y;
            }
            m_currentNumPointer = i;

        }
        public static bool isTouchReleaseScreen()
        {

            for (int i = 0; i <= m_currentNumPointer; i++)
            {
                if (arraytouchState[i] == TouchLocationState.Released)
                    return true;
            }

            return false;
        }

        public static bool isTouchPressScreen()
        {
            for (int i = 0; i <= m_currentNumPointer; i++)
            {
                if (arraytouchState[i] == TouchLocationState.Pressed)
                    return true;
            }
            return false;
        }
        public static bool isTouchPressInRect(int x, int y, int w, int h)
        {

            // if(PRINTLOG) mainCanvas.drawRoundRect(new RectF(0,0,w,h), x,y,null);

            for (int i = 0; i <= m_currentNumPointer; i++)
            {
                if (arraytouchState[i] == TouchLocationState.Pressed && arraytouchPosX[i] > x && arraytouchPosX[i] < x + w && arraytouchPosY[i] > y && arraytouchPosY[i] < y + h)
                    return true;
            }

            return false;
        }
        public static bool isTouchReleaseInRect(int x, int y, int w, int h)
        {

            // if(PRINTLOG) mainCanvas.drawRoundRect(new RectF(0,0,w,h), x,y,null);

            for (int i = 0; i <= m_currentNumPointer; i++)
            {
                if (arraytouchState[i] == TouchLocationState.Released && arraytouchPosX[i] > x && arraytouchPosX[i] < x + w && arraytouchPosY[i] > y && arraytouchPosY[i] < y + h)
                    return true;
            }

            return false;
        }
        public static bool isTouchDrapInRect(int x, int y, int w, int h)
        {
            // if(PRINTLOG) mainCanvas.drawRoundRect(new RectF(0,0,w,h), x,y,null);

            for (int i = 0; i <= m_currentNumPointer; i++)
            {
                if (arraytouchState[i] == TouchLocationState.Moved && arraytouchPosX[i] > x && arraytouchPosX[i] < x + w && arraytouchPosY[i] > y && arraytouchPosY[i] < y + h)
                    return true;
            }
            return false;
        }

    }
}
